package com.app.server.impl;

import com.app.mapper.TimeWarningMapper;
import com.app.model.TimeWarningModel;
import com.app.model.TimeWarningModel;
import com.app.server.TimeWarningService;
import com.app.vo.TimeWarningVo;
import com.app.vo.TimeWarningVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实时预警
 */
@Service
public class TimeWarningServiceImpl extends ServiceImpl<TimeWarningMapper, TimeWarningModel> implements TimeWarningService {
    @Autowired
    private TimeWarningMapper timeWarningMapper;

    @Override
    public TimeWarningVo getTimeWarningList(Integer page, Integer limit, String title) {
        Page<TimeWarningModel> page1 = new Page<>(page, limit);
        QueryWrapper<TimeWarningModel> queryWrapper = new QueryWrapper<>();
        if (title != null && !title.equals("")) {
            queryWrapper.like("title", title);
        }
        queryWrapper.orderByDesc("time");
        Page<TimeWarningModel> timePage = timeWarningMapper.selectPage(page1, queryWrapper);
        List<TimeWarningModel> timeList = timePage.getRecords();

        long count = timePage.getTotal();
        TimeWarningVo timeWarningVo = new TimeWarningVo();
        timeWarningVo.setList(timeList);
        timeWarningVo.setCount((int) count);
        return timeWarningVo;
    }
}
